package com.oren.activity.service.impl;

import com.oren.activity.mapper.ActDeploymentMapper;
import com.oren.activity.pojo.ActDeployment;
import com.oren.activity.service.ActDeploymentService;
import com.oren.base.pojo.Page;
import com.oren.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: wangshiwei
 * Date: 2018/7/31
 * Time: 14:43
 * describe:
 */
@Service
@Transactional
public class ActDeploymentServiceImpl implements ActDeploymentService {

    @Autowired
    private ActDeploymentMapper actDeploymentMapper;


    @Override
    public Page<ActDeployment> pageList(ActDeployment actDeployment, int page,int rows) {
        List<ActDeployment> list=actDeploymentMapper.pageList(actDeployment, PageUtil.getBound(page,rows));
        Integer count=actDeploymentMapper.count(actDeployment);
        return PageUtil.getPageList(list,count);
    }

    @Override
    public boolean deploymentCreate(ActDeployment actDeployment) {
        int i=actDeploymentMapper.insertEntity(actDeployment);
        if(i==0){
            return false;
        }else{
            return true;
        }
    }

    @Override
    public void delloymentDelete(String depId) {

    }

    @Override
    public ActDeployment findByPdId(String depId) {
        return actDeploymentMapper.findByPdId(depId);
    }

    @Override
    public List<Map<String, Object>> findAllDeploy() {
        List<Map<String, Object>> returnList=new ArrayList<Map<String, Object>>();
        List<ActDeployment> list=actDeploymentMapper.findAllDeploy();
        if(list!=null && list.size()>0){
            for (ActDeployment actDeployment:list) {
                Map<String ,Object> map=new HashMap<>();
                map.put("id",actDeployment.getDepId());
                map.put("text",actDeployment.getDeploymentName());
                returnList.add(map);
            }
        }
        return returnList;
    }
}
